<template>
	<div class="login-container">
		<div class="login-logo"><img src="~/assets/images/login_logo.png" /></div>
		<div class="login_box">
			<div class="main1">
			</div>
			<div class="main d-flex flex-column justify-space-between">
				<el-form :inline="true" class="login-form-box" :model="loginForm" :rules="loginRules" ref="loginForm" :hide-required-asterisk="true">
					<div class="hello">欢迎登录！</div>
					<div class="wel">
						<span>常州天正技工学校后台管理系统</span>
					</div>
					<el-form-item class="bottom-line" label="" prop="userName">
						<span class="user_img"></span>
						<el-input name="userName" v-model="loginForm.userName" autoComplete="off" placeholder="请输入账号" clearable />
					</el-form-item>
					<el-form-item label="" prop="password" class="bottom-line">
						<span class="pass_img"></span>
						<el-input
							@keyup.enter.native="handleLogin()"
							name="password"
							v-model="loginForm.password"
							autoComplete="off"
							placeholder="请输入密码"
							show-password
							clearable
						/>
					</el-form-item>
				</el-form>
				<el-button class="login-btn" native-type="submit" type="primary" :loading="loading" @click.prevent="handleLogin()">登 录</el-button>
			</div>
		</div>
	</div>
</template>
<script>
export default {
	data() {
		const validatePassword = (rule, value, callback) => {
			if (value.length < 6) {
				callback(new Error('密码不能小于6位'));
			} else {
				callback();
			}
		};
		return {
			loginForm: {
				userName: '',
				password: ''
			},
			loginRules: {
				userName: [
					{
						required: true,
						message: '请输入账号',
						trigger: 'blur'
					}
				],
				password: [
					{
						required: true,
						message: '请输入密码',
						trigger: 'blur'
					},
					{
						validator: validatePassword,
						trigger: 'blur'
					}
				]
			},
			loading: false
		};
	},
	methods: {
		// 用户名登录
		handleLogin() {
			this.$refs.loginForm.validate(valid => {
				if (valid) {
					this.loading = true;
					this.$store
						.dispatch('user/login', this.loginForm)
						.then(() => {
							this.$router
								.push({
									path: this.$route.query.redirect || '/'
								})
								.catch(console.log);
						})
						.catch(() => {
							// console.log(err)
						})
						.finally(() => {
							this.loading = false;
						});
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		}
	}
};
</script>

<style rel="stylesheet/scss" lang="scss">
$bg: #2d3a4b;

.login-container {
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100%;
	background: url('~assets/images/bg.png') no-repeat;
	background-position: center center;
	background-size: cover;
	.login-logo {
		width: 100%;
		height: auto;
		text-align: center;
		margin-top: 150px;
	}
	.login-logo img {
		width: 530px;
		height: 100px;
	}
	.login_box {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 1100px;
		position: absolute;
		left: 50%;
		top: 50%;
		margin-left: -550px;
		margin-top: -250px;
		box-shadow: 0px 1px 4px rgba(105, 105, 105, 0.1);
	}
	.main1 {
		width: 550px;
		background: url('~assets/images/login_img.png') no-repeat;
		height: 500px;
		border-radius: 12px 0 0 12px;
		background-size: 100% 100%;
		}
	.main {
		padding: 46px 46px;
		width: 550px;
		height: 500px;
		margin: auto;
		background: #fff;
		border-radius:0 12px 12px 0;
		background-size: 100% 100%;
		.hello {
			font-size: 38px;
			font-weight: 700;
			color: #3c3c3c;
		}
		.wel {
			font-size: 32px;
			line-height: 60px;
			padding-bottom: 40px;
			color: rgba(60, 60, 60, 0.6);
		}
		.wel span {
			font-size: 28px;
			color: #01c2ae;
		}
		.el-form-item {
			width: 100%;
			border-radius: 5px;
			border: 1px solid #b5b5b5;
		}
		.el-input {
			position: relative;
			font-size: 0.022917rem;
			display: inline-block;
			width: 90%;
		}
		.user_img {
			width: 25px;
			height: 25px;
			float: left;
			margin-left: 5px;
			margin-top: 8px;
			background: url('~assets/images/user.png') no-repeat 50% center;
			background-size: 100% 100%;
		}
		.pass_img {
			width:25px;
			height: 25px;
			float: left;
			margin-top: 8px;
			margin-left: 5px;
			background: url('~assets/images/pass.png') no-repeat 50% center;
			background-size: 100% 100%;
		}
		.el-form-item__error {
			top: calc(100% + 10px);
			left: 0px;
		}

		.el-form-item__label,
		.el-input__inner {
			color: #999;
			font-size: 16px;
		}
		.el-form--inline .el-form-item__content {
			display: inline-block;
			vertical-align: top;
			width: 100%;
		}
		.el-input__inner {
			background-color: transparent;
			border: none;
		}

		.bottom-line + .bottom-line {
			margin-top: 12px;
		}
	}
}

.main .el-button {
	width: 100%;
	height: 88px;
	background: linear-gradient(to right, #0184e8 0%, #01c2ae 100%);
	border-radius: 4px;
	color: #fff;
	font-size: 20px;
	border: none;
	margin-top: 60px;
	.el-button--primary {
		border-color: #4980FB;
	}
}
</style>
